package com.zmc.order.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.zmc.common.vo.OrderPayInfoVo;
import com.zmc.order.application.OrderApplicationService;
import com.zmc.order.infrastructure.bean.query.OrderManageQuery;
import com.zmc.order.infrastructure.bean.vo.OrderInfoVo;
import com.zmc.order.infrastructure.bean.vo.SubmitOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zmc.common.utils.R;


/**
 * 订单
 *
 * @author zmc
 * @email 
 * @date 2024-10-09 14:52:02
 */
@RestController
public class OrderController {


    @Autowired
    private OrderApplicationService orderApplicationService;

    /**
     * 查询订单列表
     * */
    @PostMapping("/list")
    public R list(@RequestBody OrderManageQuery query) {
        return R.ok(orderApplicationService.pageOrder(query));
    }

    /**
     * 获取订单详情
     * */
    @PostMapping("/info")
    public R orderInfo(@RequestBody OrderInfoVo vo) {
        return R.ok(orderApplicationService.orderInfo(vo.getOrderSn()));
    }

    /**
     * 提交订单
     * */
    @PostMapping("/submit")
    public R submit(@RequestBody SubmitOrderVo vo){
        orderApplicationService.submit(vo);
        return R.ok();
    }

    /**
     * 获取订单支付信息
     * */
    @PostMapping("/pay/detail")
    public R pay(@RequestBody OrderInfoVo vo){
        return R.ok(orderApplicationService.getOrderPayInfo(vo.getOrderSn()));
    }

    /**
     * 取消订单
     * */
    @PostMapping("/cancel")
    public R cancel(@RequestBody OrderInfoVo vo){
        orderApplicationService.cancelOrder(vo.getOrderSn());
        return R.ok();
    }

    /**
     * 获取订单支付第三所需信息
     * */
    @PostMapping("/pay/info")
    public R getPayInfoByOrderNo(@RequestBody OrderPayInfoVo vo) {
        return R.ok(orderApplicationService.getThirdPayInfo(vo.getOrderNo()));
    }


    /**
     * 订单支付成功详情
     * */
    @PostMapping("/pay/success")
    public R paySuccessDetail(@RequestBody OrderInfoVo vo) {
        return orderApplicationService.paySuccessDetail(vo.getOrderSn());
    }

    /**
     * 订单确认收货
     * */
    @GetMapping("/confirm/receive")
    public R confirmGetGood(@RequestBody OrderInfoVo vo) {
        orderApplicationService.confirmGetGood(vo.getOrderSn());
        return R.ok();
    }

    /**
     * 订单取消发货
     * */
    @PostMapping("/cancel/freight")
    public R cancelFreight(@RequestBody OrderInfoVo vo) {
        orderApplicationService.cancelFreight(vo.getOrderSn());
        return R.ok();
    }

    @SentinelResource(value = "sentinel", blockHandler = "blockHandler")
    @RequestMapping("/sentinel")
    public String testSentinel() {
        return "success";
    }

    public String blockHandler(BlockException e){
        return "error";
    }




}
